/*
   Author : Ahmed Adel
   Date   : 17 July 2012
   Desc   : Upon Creation We will Copy Account Owner into Opportunity Owner 
*/
trigger CopyAccountOwner on Opportunity (before insert) {

  
   if(Trigger.IsBefore && Trigger.isInsert){
   	
   	  //Get List of Accounts linked to These Opportunites
   	  List<ID> accIds = new List<ID>();
   	  for(Opportunity obj :Trigger.new){
   	  	accIds.add(obj.AccountId);
   	  }
   	  
   	  
   	  //Get Account Owners and add it to a Map
   	  Map<ID,ID> accountMap = new Map<Id,Id>();
   	  for (Account obj : [select OwnerId , id from Account where id in :accIds]){
   	  	accountMap.put(obj.id , obj.OwnerId);
   	  }
   	
   	
   	  for(Opportunity obj :Trigger.new){
   	  	 obj.OwnerId = accountMap.get(obj.AccountId);
   	  }
   	
   }
   

}